Open
Conversation
lib/match.rb
Outdated
Member
There was a problem hiding this comment.
If you're looping over something to collect items into an array, I'd rather you use map.
@turns = 13.times.map do |x|
turn = Turn.new(@opponent_a.strike, @opponent_b.strike)
if @opponent_a.strike == turn.winner
@opponent_a
else
@opponent_b
end
end
@turns.each_with_index do |winner, i|
puts "#{winner.name} won round #{i+1}!"
endI also separated the running of the turns with the reporting of the turns.
Author
There was a problem hiding this comment.
Got it. So in this case I'm interested in getting an array of winners for a given round. map returns an array so it more directly conveys what I intend to receive. Whereas in my implementation, I went in a round about way to get there by separately instantiating an array then using an iterator to populate that array. Is this a good way to look at it?
Member
|
Nice submission -- let me know if you have any questions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was a little tougher than I was anticipating. Having a better understanding of the current implementation definitely helps.